@echo off
chcp 65001 >nul
echo ========================================
echo       SQL Server防火墙配置工具
echo ========================================
echo.
echo 此脚本需要在192.168.1.99服务器上以管理员身份运行
echo.

echo [1/4] 检查当前防火墙状态...
netsh advfirewall show allprofiles state

echo.
echo [2/4] 配置SQL Server端口规则...
echo 添加SQL Server默认端口(1433)...
netsh advfirewall firewall add rule name="SQL Server (TCP-1433)" dir=in action=allow protocol=TCP localport=1433
netsh advfirewall firewall add rule name="SQL Server (UDP-1434)" dir=in action=allow protocol=UDP localport=1434

echo.
echo [3/4] 添加SQL Browser服务端口...
netsh advfirewall firewall add rule name="SQL Server Browser" dir=in action=allow protocol=UDP localport=1434

echo.
echo [4/4] 验证规则已添加...
netsh advfirewall firewall show rule name="SQL Server (TCP-1433)"
netsh advfirewall firewall show rule name="SQL Server (UDP-1434)"
netsh advfirewall firewall show rule name="SQL Server Browser"

echo.
echo ========================================
echo 配置完成！
echo 请重新运行数据库连接测试。
echo ========================================
echo.
pause